/*
 * Copyright (C) 2005 Johan Maasing johan at zoom.nu Licensed under the Apache
 * License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package nu.zoom.swing.desktop.plugin.portunis;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

/**
 * Manages keystores. Loads keystore into memory. Keeps a list of loaded
 * keystores.
 * 
 * @version $Revision: 1.1 $
 * @author $Author: johan $
 */
public interface KeyStoreHandler
{

	/**
	 * Create an empty keystore - <emp>NOT IMPLEMENTED YET </emp>
	 * 
	 * @param subject
	 *            The name of the keystore.
	 * @return A newly created keystore.
	 */
	public KeyStore createKeyStore(String subject);

	public KeyStoreWrapper loadKeyStore(File filename, KeyStoreType type,
			char[] password) throws KeyStoreException,
			NoSuchAlgorithmException, CertificateException,
			FileNotFoundException, IOException;

	/**
	 * Get all active loaded key stores.
	 * 
	 * @return The current known keystores
	 */
	public KeyStoreWrapper[] getLoadedKeyStores();

	/**
	 * Write a keystore to disk.
	 * 
	 * @param wrapper
	 *            The keystore to save.
	 * @param password
	 *            The integrity check password.
	 * @throws KeyStoreException
	 * @throws NoSuchAlgorithmException
	 * @throws CertificateException
	 * @throws IOException
	 */
	public void saveKeyStore(KeyStoreWrapper wrapper, char[] password)
			throws KeyStoreException, NoSuchAlgorithmException,
			CertificateException, IOException;

	/**
	 * Write a keystore to disk, using another name for the file than the file
	 * used to load the keystore.
	 * 
	 * @param wrapper
	 *            The keystore to write to disk.
	 * @param newFileName
	 *            The filename to use.
	 * @param password
	 * @throws KeyStoreException
	 * @throws NoSuchAlgorithmException
	 * @throws CertificateException
	 * @throws IOException
	 */
	public void saveKeyStoreAs(KeyStoreWrapper wrapper, File newFileName,
			char[] password) throws KeyStoreException,
			NoSuchAlgorithmException, CertificateException, IOException;
}
